{% extends "base_generic.html" %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h1 class="mb-0"><i class="fas fa-book"></i> 书名: {{ book.title }}</h1>
        </div>
        <div class="card-body">
            {% if perms.catalog.change_book or perms.catalog.delete_book %}
            <div class="mb-4">
                {% if perms.catalog.change_book %}
                    <a href="{% url 'book-update' book.id %}" class="btn btn-primary"><i class="fas fa-edit"></i> 更新书籍</a>
                {% endif %}
                {% if not book.bookinstance_set.all and perms.catalog.delete_book %}
                    <a href="{% url 'book-delete' book.id %}" class="btn btn-danger ms-2"><i class="fas fa-trash"></i> 删除书籍</a>
                {% endif %}
            </div>
            {% endif %}
            
            <p><i class="fas fa-user-edit"></i> <strong>作者:</strong> <a href="{{ book.author.get_absolute_url }}">{{ book.author }}</a></p>
            <p><i class="fas fa-align-left"></i> <strong>摘要:</strong> {{ book.summary }}</p>
            <p><i class="fas fa-barcode"></i> <strong>ISBN:</strong> {{ book.isbn }}</p>
            <p><i class="fas fa-language"></i> <strong>语言:</strong> {{ book.language }}</p>
            <p><i class="fas fa-tags"></i> <strong>类型:</strong> {{ book.genre.all|join:", " }}</p>

            <div class="mt-4">
                <h4><i class="fas fa-copy"></i> 副本</h4>
                
                {% if book.bookinstance_set.all %}
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>状态</th>
                            <th>预计归还日期</th>
                            <th>Imprint</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for copy in book.bookinstance_set.all %}
                        <tr>
                            <td><a href="{{ copy.get_absolute_url }}">{{copy.id}}</a></td>
                            <td class="{% if copy.status == 'a' %}text-success{% elif copy.status == 'd' %}text-danger{% else %}text-warning{% endif %}">
                                {{ copy.get_status_display }}
                            </td>
                            <td>{% if copy.status != 'a' %}{{copy.due_back}}{% endif %}</td>
                            <td>{{copy.imprint}}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                    <div class="alert alert-info">图书馆没有此书的副本。</div>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block sidebar %}
  {{ block.super }}
{% endblock %}